home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import os
- import logging
- import sys
- import textwrap
- import traceback
- import computerjanitor
- import computerjanitorapp
- _ = computerjanitorapp.setup_gettext()
-
- class UnknownCommand(computerjanitor.Exception):
-
- def __init__(self, name):
- self._str = _('Unknown command: %s') % name
-
-
-
- class UnknownCruft(computerjanitor.Exception):
-
- def __init__(self, name):
- self._str = _('Unknown cruft: %s') % name
-
-
-
- class MustBeRoot(computerjanitor.Exception):
-
- def __init__(self):
- self._str = _('computer-janitor must be run as root, sorry.')
-
-
-
- class CommandLineUserInterface(computerjanitorapp.UserInterface):
-
- def run(self, options, args):
- if self.mustberoot and os.getuid() != 0:
- raise MustBeRoot()
- os.getuid() != 0
- self.app.verify_apt_cache()
- dict = {
- 'find': self.show_cruft,
- 'cleanup': self.cleanup,
- 'ignore': self.ignore,
- 'unignore': self.unignore,
- 'help': self.help }
- if args:
- cmd = args[0]
- args = args[1:]
- else:
- cmd = 'help'
- args = []
- if cmd in dict:
- app = self.app
- app.state.load(options.state_file)
-
- try:
- dict[cmd](options, args)
- except Exception:
- e = None
- logging.debug(unicode(traceback.format_exc()))
- logging.critical(unicode(e))
- sys.exit(1)
- except:
- None<EXCEPTION MATCH>Exception
-
-
- None<EXCEPTION MATCH>Exception
- raise UnknownCommand(cmd)
-
-
- def find_cruft(self):
- list = []
- for plugin in self.pm.get_plugins():
- for cruft in plugin.get_cruft():
- list.append(cruft)
-
-
- return self.app.remove_whitelisted(list)
-
-
- def show_one_cruft(self, name, desc, s, width):
- if width is None:
- max = len(name) + len(desc)
- else:
- max = width
- max -= 9
- max -= 2
- max -= 1
- print '%-9s %.*s ' % (s, max, name)
- if desc:
- paras = desc.split('\n\n')
- for para in paras:
- for line in textwrap.wrap(para, max):
- print '%9s %s' % ('', line)
-
- print
-
-
-
-
- def show_cruft(self, options, args):
- list = []
- maxname = ''
- state = self.app.state
- for cruft in self.find_cruft():
- name = cruft.get_name()
- if options.verbose:
- desc = cruft.get_description()
- else:
- desc = None
- if state.is_enabled(name):
- s = _('removable')
- else:
- s = _('ignored')
- list.append((name, desc, s))
- if len(name) > len(maxname):
- maxname = name
- continue
-
- (rows, cols) = computerjanitorapp.get_terminal_size()
- for name, desc, s in sorted(list):
- self.show_one_cruft(name, desc, s, cols)
-
-
-
- def cleanup(self, options, args):
- crufts = { }
- for cruft in self.find_cruft():
- crufts[cruft.get_name()] = cruft
-
- if args:
- for arg in args:
- if arg not in crufts:
- raise UnknownCruft(arg)
- arg not in crufts
-
- elif options.all:
- state = self.app.state
- args = []
- for name in crufts.keys():
- if state.is_enabled(name):
- args.append(name)
- continue
- logging.info(_('Ignored: %s') % name)
-
-
- for arg in args:
- if options.no_act:
- logging.info(_('Pretending to remove cruft: %s') % arg)
- continue
- logging.info(_('Removing cruft: %s') % arg)
- crufts[arg].cleanup()
-
- for plugin in self.pm.get_plugins():
- if options.no_act:
- logging.info(_('Pretending to post-cleanup: %s') % plugin)
- continue
- logging.info(_('Post-cleanup: %s') % plugin)
- plugin.post_cleanup()
-
-
-
- def ignore(self, options, cruft_names):
- state = self.app.state
- for cruft_name in cruft_names:
- state.disable(cruft_name)
-
- if not options.no_act:
- state.save(options.state_file)
-
-
-
- def unignore(self, options, cruft_names):
- state = self.app.state
- for cruft_name in cruft_names:
- state.enable(cruft_name)
-
- if not options.no_act:
- state.save(options.state_file)
-
-
-
- def help(self, options, args):
- self.app.parser.print_help()
-
-
-